import QtQuick 2.0
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.12
import "../components"
Item {
    id: root

    function refreshModelList(programList){
        programsModel.clear()
        console.log("刷新ModelList，获取列表长度: " + programList.length)
        for(let i = 0; i < programList.length; i ++){
            programsModel.append({
                                     "Serial": i+1,
                                     "Id": programList[i]["Id"],
                                     "IsDefault": programList[i]["IsDefault"],
                                     "ProgramName": programList[i]["ProgramName"],
                                     "Duration": programList[i]["Duration"],
                                     "StepNum": programList[i]["StepNum"],
                                     "CreateDate": programList[i]["CreateDate"],
                                     "Memo": programList[i]["Memo"],
                                 })
        }
    }

    anchors.fill: parent

    Rectangle{
        y: 0
        height: 10*dp
        width: parent.width
        x: 0
    }
    Rectangle{                      // 扩增程序列表 ============================================================

        y: 70*dp
        height: root.height-70*dp
        width: root.width

        ListView{
            id: programsView
            model: programsModel
            anchors.fill: parent
            delegate: programDelegate
            ScrollBar.vertical: ScrollBar{}
        }

        Component{
            id: programDelegate

            ProgramListLine{
                programSerial: Serial
                programId: Id
                programName: ProgramName
                programIsDefault: IsDefault
                programDuration: Duration
                programCreateDate: CreateDate
                programMemo: Memo
            }
        }
        ListModel{
            id: programsModel
        }

    }
    Item{
        y: 70*dp
        height: root.height-70*dp
        width: root.width
        visible: programsModel.count === 0
        Image{
            width: 300*dp
            height: 280*dp
            anchors.centerIn: parent
            anchors.verticalCenterOffset: -100*dp
            source: "qrc:/picture/empty.png"
            Text{
                text: "还没有程序，快去创建吧~"
                font.pixelSize: config.fontsize + 2
                anchors.horizontalCenter: parent.horizontalCenter
                y: 280*dp
                color: "#AAAAAA"
            }
        }
    }

    Rectangle{                      // 扩增程序表头 ===========================================================
        y: 10*dp
        height: 60*dp
        color: "#F7F8FA"
        width: root.width
        Row{
            spacing: 8*dp
            height: parent.height
            width: root.width
            Item{
                height: parent.height
                width: root.width * 0.08
                Text {
                    anchors.centerIn: parent
                    text: "序号"
                    font.pixelSize: config.fontsize
                    font.bold: true
                }
            }
            Item{
                height: parent.height
                width: root.width * 0.08
                Text {
                    anchors.centerIn: parent
                    text: "编号"
                    font.pixelSize: config.fontsize
                    font.bold: true
                }
            }

            Item{
                height: parent.height
                width: root.width * 0.15
                Text {
                    anchors.centerIn: parent
                    text: "程序名称"
                    font.pixelSize: config.fontsize
                    font.bold: true
                }
            }
            Item{
                height: parent.height
                width: root.width * 0.15
                Text {
                    anchors.centerIn: parent
                    text: "运行时间"
                    font.pixelSize: config.fontsize
                    font.bold: true
                }
            }
            Item{
                height: parent.height
                width: root.width * 0.15
                Text {
                    anchors.centerIn: parent
                    text: "修改时间"
                    font.pixelSize: config.fontsize
                    font.bold: true
                }
            }
            Item{
                height: parent.height
                width: root.width * 0.2
                Text {
                    anchors.centerIn : parent
                    text: "备注"
                    font.pixelSize: config.fontsize
                    font.bold: true
                }
            }
            Item{
                height: parent.height
                width: root.width * 0.12
                Text {
                    anchors.centerIn : parent
                    text: "操作"
                    font.pixelSize: config.fontsize
                    font.bold: true
                }

            }
        }
    }




}
